/*
 * Created by Wildish on 2016-10-28
 *
 * Contact me with keithknight@qq.com
 *
 * Copyright (c) 2016 Wildish
 *
 */

package com.wildish.qcface.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.wildish.customprogressdialog.CustomProgressDialog;
import com.wildish.qcface.R;
import com.wildish.qcface.util.Global;

import org.apache.commons.lang3.StringUtils;

/**
 *
 * Created by Wildish on 2016-10-26.
 */
public class LoginActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_login);
        Global.initStoredInfo(this);

        if(StringUtils.isNotBlank(Global.cardId)) {
            ((EditText)findViewById(R.id.et_card)).setText(Global.cardId);
        }
        if(StringUtils.isNotBlank(Global.name)) {
            ((EditText)findViewById(R.id.et_name)).setText(Global.name);
        }

        findViewById(R.id.btn_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String cardId = ((EditText)findViewById(R.id.et_card)).getText().toString();
                String name = ((EditText)findViewById(R.id.et_name)).getText().toString();

                if(StringUtils.isNotBlank(cardId) && StringUtils.isNotBlank(name)) {
                    Global.setCardId(cardId);
                    Global.setName(name);

                    Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                    LoginActivity.this.startActivity(intent);
                    LoginActivity.this.finish();
                }
            }
        });
    }
}
